package ynu.sxp.demoapp.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import ynu.sxp.demoapp.entity.Cart;
import ynu.sxp.demoapp.repository.CartRepository;
import ynu.sxp.demoapp.service.CartService;

import java.util.List;
import java.util.UUID;

@Service
public class CartServiceImpl implements CartService {
    private final CartRepository cartRepository;

    @Autowired
    public CartServiceImpl(CartRepository cartRepository) {
        this.cartRepository = cartRepository;
    }

    @Override
    public List<Cart> getCartByUserId(String userId) {
        return cartRepository.findByUserId(userId);
    }

    @Override
    public List<Cart> getCartByUserIdAndBusinessId(String userId, Integer businessId) {
        return cartRepository.findByUserIdAndBusinessId(userId, businessId);
    }

    @Override
    public void addToCart(Cart cart) {
        cartRepository.save(cart);
    }

    @Override
    public void updateCart(Cart cart) {
        cartRepository.save(cart);
    }

    @Override
    public void removeFromCart(UUID cartId) {
        cartRepository.deleteById(cartId);
    }
}